package com.qu.waibao.my.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qu.waibao.R;
import com.qu.waibao.base.BaseRecyclerAdapter;
import com.qu.waibao.bean.Order;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/23.
 */

public class AcceptAdapter extends BaseRecyclerAdapter<Order> {
    public AcceptAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new AcceptViewHolder(mInflater.inflate(R.layout.accpet_recycler_item,parent,false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, Order item, int position) {
        AcceptViewHolder publishViewHolder = (AcceptViewHolder) holder;
        String status = item.getState();
        publishViewHolder.tv_ordercode.setText(item.getOrdercode());
        publishViewHolder.tv_status.setText(status);
        publishViewHolder.tv_remark.setText(item.getRemark());
        if(item.getMoney_total().equals("0.00")){
            publishViewHolder.tv_money.setVisibility(View.GONE);
        }else {
            publishViewHolder.tv_money.setText("¥"+item.getMoney_total());
        }
        publishViewHolder.tv_type.setText(item.getServicecategoryname());
        publishViewHolder.tv_time.setText(item.getCreatedate());
        if(status.equals("已完成") && item.getIfcommented_server().equals("0")){
            publishViewHolder.rl_comment.setVisibility(View.VISIBLE);
        }else {
            publishViewHolder.rl_comment.setVisibility(View.GONE);
        }
        publishViewHolder.tv_comment.setTag(position);
        publishViewHolder.tv_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = (int) v.getTag();
                if(onItemButtonClickListener != null){
                    onItemButtonClickListener.onCommentItemClick(position);
                }
            }
        });
    }
    class AcceptViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_ordercode)
        TextView tv_ordercode;
        @BindView(R.id.tv_status)
        TextView tv_status;
        @BindView(R.id.tv_remark)
        TextView tv_remark;
        @BindView(R.id.tv_money)
        TextView tv_money;
        @BindView(R.id.tv_type)
        TextView tv_type;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_comment)
        TextView tv_comment;
        @BindView(R.id.rl_comment)
        RelativeLayout rl_comment;
        public AcceptViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

    public interface OnCommentItemClickListener{
        void onCommentItemClick(int position);
    }
    private OnCommentItemClickListener onItemButtonClickListener;
    public void setOnItemButtonClickListener(OnCommentItemClickListener onItemButtonClickListener){
        this.onItemButtonClickListener = onItemButtonClickListener;
    }
}
